﻿@model List<WebEntities.Models.WebInfo.Experts>
@{
    ViewBag.Title = "网站管理平台_专家人物视图";
}
@section HeadContent
{
    <link href="/Content/data-view.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        var prepareData = function (data) {
            data.shortName = Ext.util.Format.ellipsis(data.ExpertName, 15);
            data.sizeString = Ext.util.Format.fileSize(data.ExpertName);
            //  data.dateString = Ext.Date.format(data.lastmod, "m/d/Y g:i a");

            return data;
        };

        var selectionChanged = function (selModel, selected) {
            var l = selected.length, s = l != 1 ? 's' : '';
            App.Panel1.setTitle('专家人物视图 (' + l + ' item' + s + ' selected)');
        };

        var onDeleteImgSuccess = function (response, data) {
            Ext.Msg.show({ title: '提示', msg: data.result.Msg, buttons: Ext.Msg.OK, icon: Ext.Msg.INFO, modal: true,
                fn: function (btn) {
                    var imgview = App.ImageView;
                    imgview.store.reload();
                }
            });
        };

        var onDeleteImgFailure = function (response, data) {
            Ext.Msg.show({ title: '提示', msg: data.result.Msg, buttons: Ext.Msg.OK, icon: Ext.Msg.ERROR, modal: true });
        };
        
    </script>
}
@(Html.X().Menu()
    .ID("Grid1CtxMenu")
    .Items(
        Html.X().MenuItem().Text("编辑").Icon(Icon.BookEdit)
            .DirectEvents(de =>
            {
                de.Click.Action = "EditExpertsWindow";
                de.Click.ExtraParams.Add(new Parameter("ExpertsId", "this.parentMenu.dataRecord.data.ExpertID", ParameterMode.Raw));

            }),
            Html.X().MenuItem().Text("删除").Icon(Icon.Cross).Listeners(ls => ls.Click.Handler = "App.BtnDeleteSel.getEl().dom.click()")
    )
)
@Html.X().Hidden().ID("DeleteHint").Text("是否要删除选中的内容？")
@Html.X().Hidden().ID("hidCataID")
@(Html.X().Viewport()
    .Layout("fit")
    .Items(
        Html.X().Panel()
            .ID("Panel1")
            .Cls("images-view")
            .Frame(true)
            .Collapsible(true)
            .Layout(LayoutType.Fit)
            .Title("专家人物视图 (0 items selected)")
            .Items(
                Html.X().DataView()
                         .ID("ImageView")
                         .Store(
                         Html.X().StoreForModel()
                             .AutoSync(true)
                                  .PageSize(20).ID("Store1")
                             .ShowWarningOnFailure(false)
                             .Proxy(proxy => proxy.Add(Html.X().AjaxProxy()
                                         .Url(Url.Action("GetAllExperts")).ExtraParams(ep => ep.Add(new { cataid = ViewBag.CataID }))
                                 .Reader(Html.X().JsonReader().Root("data"))
                                 .Writer(writer => new JsonWriter { AllowSingle = true, Root = "data" })
                                     .API(api => { api.Destroy = Url.Action("DeleteExperts"); })
                             ))
                             .Listeners(ls => ls.Write.Fn = "ext.net.comjs.onGridChange")
                     )
                    //.MultiSelect(true)
                    .OverItemCls("x-item-over")
                    .ItemSelector("div.thumb-wrap")
                    .EmptyText("No images to display")
                    .TrackOver(true)
                    .Tpl(
                        Html.X().XTemplate()
                            .Html(
                                @<text>
                                    <tpl for=".">
								        <div class="thumb-wrap" id="{ExpertID}">
									        <div class="thumb"><img src="{ExpertPic}"  title="{ExpertName}"></div>
									        <span class="x-editable">{ExpertName}</span>
								        </div>
							        </tpl>
                                    <div class="x-clear">
                                    </div>
                                </text>
                            )
                    )
                    .PrepareData("prepareData")
                    .Listeners(l =>
                    {
                        l.SelectionChange.Fn = "selectionChanged";
                        l.ItemContextMenu.Handler = "e.preventDefault(); App.Grid1CtxMenu.dataRecord = this.store.getAt(index); App.Grid1CtxMenu.showAt(e.getXY());";
                    })
                         .DirectEvents(de =>
                         {
                             de.ItemDblClick.Action = "EditExpertsWindow";
                             de.ItemDblClick.ExtraParams.Add(new Parameter("ExpertsId", "App.ImageView.getSelectedNodes()[0].id", ParameterMode.Raw));

                         })
                    .Plugins(
                        Html.X().DataViewDragSelector(),
                        Html.X().DataViewLabelEditor().DataIndex("name")
                    )
                ).TopBar(
                        Html.X().Toolbar()
                            .Items(
                                Html.X().Button().Text("新建").Icon(Icon.Add)
                                    .DirectEvents(de =>
                                    {
                                        de.Click.Action = "NewExpertsWindow";
                                        de.Click.ExtraParams.Add(new Parameter("cataId", "App.hidCataID.getValue()", ParameterMode.Raw));
                                        de.Click.Success = "";
                                        de.Click.Failure = "";
                                    }),
                                Html.X().Button().ID("BtnDeleteSel").Text("删除").Icon(Icon.Cross)
                                .DirectEvents(de =>
                                {
                                    de.Click.Url = Url.Action("DeleteExperts");
                                    de.Click.ExtraParams.Add(new Parameter("id", "App.Grid1CtxMenu.dataRecord.data.ExpertID", ParameterMode.Raw));
                                    de.Click.Confirmation.ConfirmRequest = true;
                                    de.Click.Confirmation.Title = "提示";
                                    de.Click.Confirmation.Message = "是否要删除选中的数据？";
                                    de.Click.EventMask.ShowMask = true;
                                    de.Click.EventMask.Msg = "正在保存";
                                    de.Click.Success = "onDeleteImgSuccess";
                                    de.Click.Failure = "onDeleteImgFailure";
                                })
                            )
                    )
           .BottomBar(
                     Html.X().PagingToolbar().StoreID("Store1").HideRefresh(true)
                 )
    )
)
